a = int(input())
maxot = 0
if a > 999 and a < 10000:
    for p1 in range(4):
        for p2 in range(p1, 4):
            str_a = str(a)
            b = int(str_a[p1:p2 + 1])
            d = 2
            pr = 0
            while d ** 2 <= b:
                if b % d == 0:
                    pr = 1
                d += 1
            if pr == 0:
                if maxot < b:
                    maxot = b
print(maxot)
